All Questions
24 questions
4votes
2answers
5kviews
Build a flat List from a Tree structure in Java
I have a Tree structure represented by a List, which I want to get it flattened. I wrote the function below: ...
1vote
1answer
62views
Depth-first traversal implementation in Java (by recursion)
I implemented a recursive depth-first traversal, with all three traversal modes in this function. Is this the most succinct way to write the code? ...
3votes
1answer
3kviews
Java n-ary Tree class with custom made methods and nested Node class
I'm a beginner and I wrote this (working) code for n-ary tree. The specifics: Each node is to be built with an integer value. Each node has a variable number of children. The nodes should have an ...
1vote
2answers
766views
Find all root to leaf paths in binary tree
Description: Given a binary tree, return all root-to-leaf paths. Leetcode ...
2votes
1answer
522views
Find minimum depth in a binary tree
Description: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node ...
3votes
2answers
1kviews
Algorithm that generate all possible strings from N Tuples. Found Brute Force version, Recursive Version uses a Tree?
I am trying to figure out a solution for a problem. Consider the following tuples (it could be any number of tuples, I am using four in this example): {A, B, C, D} ...
4votes
1answer
524views
Convert Ternary Expression to a Binary Tree
This is programming question I came across (geeksforgeeks) : Given a string that contains ternary expressions. The expressions may be nested, task is convert the given ternary expression to a binary ...
1vote
3answers
449views
Exercise - count binary-tree nodes with 1 leaf and 1 internal node as children
I'm currently working through "Algorithms in java" by Robert Sedgewick (3rd edition, german version) on my own and am trying to solve one of the exercises there. The exercise Write a program that ...
2votes
0answers
373views
Follow-up 1: Compare 2 unordered, rooted trees for shape-isomorphism
The previous post can be found here. In the previous post I tried to solve an exercise but found through the answer of Peilonrayz a bug in the code and 2 more while fixing it. These have now been ...
2votes
2answers
1kviews
Compare 2 unordered, rooted trees for shape-isomorphism
I'm currently working through "Algorithms in java" by Robert Sedgewick (3rd edition, german version) on my own and am trying to solve one of the exercises there. Edit: This question now also has a ...
1vote
1answer
2kviews
Recursive Preorder Traversal
For today, I tackled this coding challenge question: Given a binary tree, write a method to recursively traverse the tree in the preorder manner. Mark a node as visited by adding its data to the list -...
6votes
1answer
2kviews
Code smell when recursively returning a List
So this is part of my AVL tree implementation, namely the infix representation of the tree. Since I wanted to use a recursive method to stay close to the original algorithm and want to return a list, ...
5votes
2answers
252views
Binary Search tree deletion optimization
I have just started implementing Binary Search tree on my own without using any tutorials online. Please have a look and suggest how can I make code less cluttered and more faster. Right now I am ...
6votes
5answers
11kviews
DFS in Binary Tree
I have written this code for DFS in a binary tree and would like improvements on it. ...
5votes
2answers
1kviews
Algorithm that checks if a tree is full and complete
I am trying to write a method that will return true if a binary tree is full and complete (each node has 2 children or none and all the leaves of the tree are at the same depth). My idea is to use ...